package com.pds.web.monitor.controller;


import com.pds.common.core.controller.BaseController;
import com.pds.common.core.domain.R;
import com.pds.common.core.page.TableDataInfo;
import com.pds.common.utils.SecurityUtils;
import com.pds.web.monitor.domain.MonitorContractDTO;
import com.pds.web.monitor.domain.PdsMonitorContract;
import com.pds.web.monitor.domain.PdsMonitorContractVO;
import com.pds.web.monitor.dto.ContractDTO;
import com.pds.web.monitor.service.IPdsMonitorContractService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@RequestMapping("/contract")
public class PdsMonitorContractController extends BaseController {

    @Autowired
    private IPdsMonitorContractService pdsMonitorContractService;


    /**
     * 新增合同
     * @param pdsMonitorContract
     * @return
     */
    @PostMapping("/addContract")
    public R<PdsMonitorContract> add(@RequestBody PdsMonitorContract pdsMonitorContract){
        return R.ok(pdsMonitorContractService.insertContract(pdsMonitorContract));
    }

    /**
     * 更新合同
     * @param pdsMonitorContract
     * @return
     */
    @PostMapping("/updateContract")
    public R<Boolean> update(@RequestBody PdsMonitorContract pdsMonitorContract){
        return R.ok(pdsMonitorContractService.updateContract(pdsMonitorContract));
    }

    /**
     * 删除合同 --根据id
     * @param id --主键
     * @return
     */
    @GetMapping("/deleteContract")
    public R<Boolean> delete(@RequestParam Long id){
        return R.ok(pdsMonitorContractService.deleteContract(id));
    }

    /**
     * 企业查询合同 -- 分页/条件:contractName,monitorProject,contractCode
     * @param monitorContractDTO -- 合同名称，检测项目，合同编号
     * @return
     */
    @GetMapping("/listCompanyContract")
    public TableDataInfo listCompanyContract(MonitorContractDTO monitorContractDTO){
//        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
//        Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
        Long companyId = pdsMonitorContractService.getCompanyId(241L);
        monitorContractDTO.setCompanyId(companyId);
        startPage();
        List<PdsMonitorContractVO> pdsMonitorContractVOList = pdsMonitorContractService.listCompanyContract(monitorContractDTO);
        return getDataTable(pdsMonitorContractVOList);
    }

    /**
     * 机构查询合同 -- 分页/条件:contractName,monitorProject,contractCode
     * @param monitorContractDTO -- 合同名称，检测项目，合同编号
     * @return
     */
    @GetMapping("/listOrganizationContract")
    public TableDataInfo listOrganizationContract(MonitorContractDTO monitorContractDTO){
//        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
//        Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
        Long organizationId = pdsMonitorContractService.getOrganizationId(233L);
        monitorContractDTO.setOrganizationId(organizationId);
        startPage();
        List<PdsMonitorContractVO> pdsMonitorContractVOList = pdsMonitorContractService.listOrganizationContract(monitorContractDTO);
        return getDataTable(pdsMonitorContractVOList);
    }

    /**
     * 分页查询全部合同 -- 分页/条件:contractName,monitorProject,contractCode
     * @param contractDTO -- 合同名称，检测项目，合同编号
     * @return
     */
    @GetMapping("/listAll")
    public TableDataInfo listContract(ContractDTO contractDTO){
        startPage();
        List<PdsMonitorContractVO> pdsMonitorContractVOList = pdsMonitorContractService.listAll(contractDTO);
        return getDataTable(pdsMonitorContractVOList);
    }

    /**
     * 根据id查询合同
     * @param id -- 主键
     * @return
     */
    @GetMapping("/queryById")
    public R<PdsMonitorContractVO> queryById(@RequestParam Long id){
        return R.ok(pdsMonitorContractService.queryById(id));
    }

}
